/******************************************
Copyright (c) 2012 Mohamed Saad IBN SEDDIK

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

******************************************/
#ifndef M6DBUS_H
#define M6DBUS_H

#include <QObject>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include "modbus/modbus.h"

#define Offcet 0x1A

using namespace std;


class M6dbus : public QObject
{
    Q_OBJECT
public:
    explicit M6dbus(char* IP,int prt,QObject *parent = 0);
    ~M6dbus();

    int updateRegTab(uint16_t*);
    int writeReg(int,int);
    int getRegNum(int);

    int updateAll();

    int turnLightOn(int);
    int turnLightOn(int,int);
    int turnLightOff();
    int turnLightOff(int);

    int turnLaserOn(int);
    int turnLaserOff(int);

    int setAutoDepth();
    int setAutoDirec();
    int setAutoAltit();
    int setAutoProxm();

    int resetCountAh();

    int setModePower();
    int setModeLogic();

    int setCamera(int);
    int setCamLights(int);
    int clrCamLights(int);
    int setCameraBUP(int);
    int setCameraBDO(int);
    int setCameraBLE(int);
    int setCameraBRI(int);
    int setCameraBSE(int);
    int setCamTilt(int);

    int getClockR4Wr();
    int getClockR4Rd();
    int* getAuvTime();
    int setAuvTime(int[4]);

    int getAlarms();
    bool getWaterIn1();
    bool getWaterIn2();
    bool getWaterIn3();
    bool getWaterInCam();
    bool getHiTempIn();
    bool getLowU1();
    bool getLowU2();
    bool getHighI1();
    bool getHighI2();
    bool getMaxDepth();
    bool getErrRConf();
    bool getErrI2C();
    bool getErrSPI();
    bool getErrLink();

    int getDepth();
    int getDirec();
    int getU1();
    int getU2();
    int getI1();
    int getI2();
    int getTempMB();
    int getTempOut();
    int getTempEx1();
    int getTempEx2();
    int getTempEx3();
    int getCapBat1();
    int getCapBat2();
    int getVersion();

    int setPropFrRi(int);
    int setPropFrLe(int);
    int setPropReRi(int);
    int setPropReLe(int);
    int setPropVert(int);

signals:

public slots:

private:
    modbus_t *Modbus;
    uint16_t regTab[48];
    //Variables (raw value)
    int depth, direction, U1, I1, U2, I2, tempMB,
        tempOut, tempEx1, tempEx2, tempEx3, capBat1, capBat2, version;
    int auvTime[4];
    //Alarms
    int alarms;
    bool waterIn1, waterIn2, waterIn3, waterInC, hiTempIn, lowU1, lowU2,
        highI1, highI2, maxDepth, errRConf, errI2C, errSPI, errLink;

};

#endif // M6DBUS_H
